package com.medicine.hbp.sp;

import com.medicine.hbp.mob.UserInfosVo;

import android.content.Context;
import android.content.SharedPreferences;

public class LoginSp {
	private static final String LOGIN_SP="login";

	private static final String LOGIN_ID="id";
	private static final String LOGIN_USERID="userId";
	private static final String LOGIN_USERNAME="userName";
	private static final String LOGIN_USERINTEGRAL="userIntegral";
	private static final String LOGIN_USERATTCOUNT="userAttCount";
	private static final String LOGIN_USERFANSCOUNT="userFansCount";
	private static final String LOGIN_USERSIGNATURE="userSignature";
	private static final String LOGIN_USERAREA="userArea";
	private static final String LOGIN_TOKEN="token";
	private static final String LOGIN_SEX="sex";
	private static final String LOGIN_PROVICE="provice";
	private static final String LOGIN_CITY="city";
	private static final String LOGIN_DISTRICT="district";
	private static final String LOGIN_USERHEAD="head";

	private static SharedPreferences preferences;
	public static void setUser(UserInfosVo userInfo,Context context){
//		if(null!=userInfo.id){
//			setId(userInfo.id,context);
//		}
		if(null!=userInfo.userId){
			setUserId(userInfo.userId,context);
		}
		if(null!=userInfo.userName){
			setUserName(userInfo.userName,context);
		}
//		if(null!=userInfo.sex){
//			setSex(userInfo.sex,context);
//		}
//		if(null!=userInfo.sex){
//		setProvice(userInfo.sex,context);
//	}
//		if(null!=userInfo.sex){
//		setCity(userInfo.sex,context);
//	}
//		if(null!=userInfo.sex){
//		setDistrict(userInfo.sex,context);
//	}
		if(null!=userInfo.userIntegral){
			setUserIntegral(userInfo.userIntegral,context);
		}
		if(null!=userInfo.userAttCount){
			setUserAttcount(userInfo.userAttCount,context);
		}
		if(null!=userInfo.userFansCount){
			setUserFanscount(userInfo.userFansCount,context);
		}
		if(null!=userInfo.userSignature){
			setUserSignature(userInfo.userSignature,context);
		}
		if(null!=userInfo.userArea){
			setUserArea(userInfo.userArea,context);
		}
//		if(null!=userInfo.token){
//			setToken(userInfo.token,context);
//		}

	}

	public static void exitUser(Context context){
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		preferences.edit().clear().commit();
	}
	/**
	 * Token
	 */
	public static String getToken(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_TOKEN, "");
	}

	public static void setToken(String token,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_TOKEN, token).commit();
	}
//	/**
//	 * ID
//	 * @return
//	 */
//	public static Integer getId(Context context) {
//		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
//		return preferences.getInt(LOGIN_ID, 0);
//	}
//
//	public static void setId(Integer id,Context context) {
//		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
//		preferences.edit().putInt(LOGIN_ID, id).commit();
//	}
	/**
	 * 用户ID
	 * @return
	 */
	public static Integer getUserId(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		return preferences.getInt(LOGIN_USERID, 0);
	}

	public static void setUserId(Integer userid,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putInt(LOGIN_USERID, userid).commit();
	}
	/**
	 * 用户名称
	 * @return
	 */
	public static String getUserName(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_USERNAME, "");
	}

	public static void setUserName(String username,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_USERNAME, username).commit();
	}
	/**
	 * 用户头像
	 * @return
	 */
	public static String getUserHead(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_USERHEAD, "");
	}

	public static void setUserHead(String head,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_USERHEAD, head).commit();
	}
	/**
	 * 用户性别(Y男 N女)
	 * @return
	 */
	public static String getSex(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_SEX, "");
	}

	public static void setSex(String sex,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_SEX, sex).commit();
	}
	/**
	 * 省
	 * @return
	 */
	public static String getProvice(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_PROVICE, "");
	}

	public static void setProvice(String Provice,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_PROVICE, Provice).commit();
	}
	/**
	 * 市
	 * @return
	 */
	public static String getCity(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_CITY, "");
	}

	public static void setCity(String City,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_CITY, City).commit();
	}
	/**
	 * 区
	 * @return
	 */
	public static String getDistrict(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_DISTRICT, "");
	}

	public static void setDistrict(String District,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_DISTRICT, District).commit();
	}

	/**
	 * 用户积分
	 * @return
	 */
	public static Integer getUserIntegral(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getInt(LOGIN_USERINTEGRAL, 0);
	}

	public static void setUserIntegral(Integer UserIntegral,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putInt(LOGIN_USERINTEGRAL, UserIntegral).commit();
	}
	/**
	 * 用户关注数
	 * @return
	 */
	public static Integer getUserAttcount(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getInt(LOGIN_USERATTCOUNT, 0);
	}

	public static void setUserAttcount(Integer UserAttcount,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putInt(LOGIN_USERATTCOUNT, UserAttcount).commit();
	}
	/**
	 * 用户粉丝数
	 * @return
	 */
	public static Integer getUserFanscount(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getInt(LOGIN_USERFANSCOUNT, 0);
	}

	public static void setUserFanscount(Integer UserFanscount,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putInt(LOGIN_USERFANSCOUNT, UserFanscount).commit();
	}

	/**
	 * 用户签名
	 * @return
	 */
	public static String getUserSignature(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_USERSIGNATURE, "");
	}

	public static void setUserSignature(String userSignature,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_USERSIGNATURE, userSignature).commit();
	}

	/**
	 * 用户所在地域
	 * @return
	 */
	public static String getUserArea(Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		return preferences.getString(LOGIN_USERAREA, "");
	}

	public static void setUserArea(String userArea,Context context) {
		preferences = context.getSharedPreferences(LOGIN_SP,
				Context.MODE_PRIVATE);
		preferences.edit().putString(LOGIN_USERAREA, userArea).commit();
	}
}
